package com.Java.train.business.consumer;


import cn.hutool.json.JSON;
import cn.hutool.json.JSONUtil;
import com.Java.train.business.entity.DTO.ConfirmOrderReqDTO;
import com.Java.train.business.enums.RabbitQueueEnums;
import com.Java.train.business.service.ConfirmOrderService;
import jakarta.annotation.Resource;
import org.slf4j.MDC;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class RabbitOrderConsumer {
    // 利用RabbitListener来声明要监听的队列信息
    // 将来一旦监听的队列中有了消息，就会推送给当前服务，调用当前方法，处理消息。
    // 可以看到方法体中接收的就是消息体的内容
    @Resource
    private ConfirmOrderService confirmOrderService;
    @RabbitListener(queues = "ConfirmOrder.queue")
    public void listenSimpleQueueMessage(String msg) throws InterruptedException {
        ConfirmOrderReqDTO confirmOrderReqDTO = JSONUtil.toBean(msg, ConfirmOrderReqDTO.class);
        String logId = confirmOrderReqDTO.getLogId();
        MDC.put("LOG_ID", logId);
        System.out.println("spring 消费者接收到消息：【" + confirmOrderReqDTO + "】");
        confirmOrderService.doConfim(confirmOrderReqDTO);
    }
}
